package com.htfyun.ft.fragment.factory;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.htfyun.ft.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class FragmentScreen extends FactoryBaseFragment {

    private final int[] SHOW_COLORS = {
            Color.WHITE,
            Color.RED,
            Color.GREEN,
            Color.BLUE,
            Color.YELLOW,
            Color.CYAN,
            Color.MAGENTA,
            Color.LTGRAY,
            Color.GRAY,
            Color.DKGRAY,
            Color.BLACK,
    };

    private View container;
    private View layoutBtn;

    private int currentColorIndex;


    @Override
    protected int getLayoutRes() {
        return R.layout.fragment_factory_screen;
    }

    @Override
    protected void onInitView(@Nullable Bundle savedInstanceState) {
        super.onInitView(savedInstanceState);

        container = findViewById(R.id.container);
        layoutBtn = findViewById(R.id.layoutBtn);
        layoutBtn.setVisibility(View.GONE);
    }

    @Override
    protected void onVisible() {
        super.onVisible();

        currentColorIndex = 0;
        container.setBackgroundColor(SHOW_COLORS[currentColorIndex]);
        container.setOnClickListener(onClickListener);
        layoutBtn.setVisibility(View.GONE);

    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            currentColorIndex ++;

            if (currentColorIndex >= SHOW_COLORS.length) {
                currentColorIndex = 0;

                layoutBtn.setVisibility(View.VISIBLE);
                container.setOnClickListener(null);

            }

            container.setBackgroundColor(SHOW_COLORS[currentColorIndex]);
        }
    };

}
